////
////  TGAlertView.m
////  YouDeOptimization
////
////  Created by apple on 2018/4/18.
////  Copyright © 2018年 apple. All rights reserved.
////
//
//#import "TGAlertView.h"
//
//
//@interface TGAlertView()<UITextFieldDelegate>
//{
//    TGConfrimBlock _confrimBlock;
//    
//}
//@property (nonatomic, strong)UIWindow * wnd;
//@property (nonatomic, strong)UIView * contentView;
//@property (nonatomic, strong)UIView * hLine;
//@property (nonatomic, strong)UIView * vLine;
//@property (nonatomic, strong)UIButton * confrimButton;
//@property (nonatomic, strong)UIButton * cancelButton;
//@property (nonatomic, strong)NSArray * titleArray;
//
//@property (nonatomic, strong)UILabel * contentLabel;
//
//@property (nonatomic ,assign)NSInteger tF;
//
//@property (nonatomic ,strong)UITextField * textFild ;
//
//@property (nonatomic ,strong)UIButton *leftB ;
//
//@end
//
//@implementation TGAlertView
//
//
//#pragma mark - init方法
////- (instancetype)initWithTitleArray:(NSArray *)titleArray AndTheConfrimString:(NSString *)confrimStr AndTheCancelString:(NSString *)cancelStr AndTheConfrimBlock:(TGConfrimBlock)confrimBlock AndBool:(BOOL)boolview
////{
////    self = [super init];
////    if (self)
////    {
////
////
////        _confrimBlock = confrimBlock;
////        self.titleArray = titleArray;
////        //创建wnd
////        [self createWindow];
////        //创建contentView
////        [self createContentView];
////        for (int i = 0; i < titleArray.count; i++) {
////            NSString * title = titleArray[i];
////            CGRect frame = CGRectMake(0, TGCaculate(27) + TGCaculate(30) * i, TGCaculate(238), TGCaculate(13));
////            [self createTitleWithFrame:frame AndTitle:title AndTag:i];
////
////        }
////
////
////        if (boolview == YES)
////        {
////            UITextField *textF = [[UITextField alloc]init ] ;
////            textF.text = @"1" ;
////            _tF = 1 ;
////
////            textF.textAlignment = NSTextAlignmentCenter ;
////            textF.borderStyle = UITextBorderStyleLine;
////            textF.frame = CGRectMake(TGCaculate(86),TGCaculate(60),TGCaculate(68),TGCaculate(30)) ;
////            _tF = [textF.text intValue ];
////            textF.layer.borderColor = [[UIColor colorWithWhite:0.9 alpha:1] CGColor];
////            textF.layer.borderWidth =1 ;
////            textF.delegate = self ;
////            [_contentView addSubview:textF];
////            _textFild = textF ; //记录这个文本框
////
////            UIButton * left = [[UIButton alloc]init ] ;
////            left.backgroundColor = [UIColor grayColor] ;
////            [left setTitle:@"-" forState:UIControlStateNormal];
////            left.frame = CGRectMake(TGCaculate(56),TGCaculate(66),TGCaculate(20),TGCaculate(20)) ;
////            left.layer.cornerRadius = TGCaculate(10) ;
////            left.layer.masksToBounds = YES ;
////            left.backgroundColor = RGB(0, 175, 188) ;
////            [_contentView addSubview:left ];
////            [left addTarget:self action:@selector(leftButtonTarget) forControlEvents:UIControlEventTouchUpInside ];
////            _leftB = left ;
////
////
////            UIButton * right = [[UIButton alloc]init ] ;
////            [right setTitle:@"+" forState:UIControlStateNormal] ;
////            right.layer.cornerRadius = TGCaculate(10) ;
////            right.layer.masksToBounds = YES ;
////            right.backgroundColor = RGB(0, 175, 188) ;
////            right.frame = CGRectMake(TGCaculate(164),TGCaculate(66),TGCaculate(20),TGCaculate(20)) ;
////            [_contentView addSubview:right] ;
////            [right addTarget:self action:@selector(rightButtonTarget) forControlEvents:UIControlEventTouchUpInside ];
////
////
////        }
////        [self createLine];
////        [self createCancelButtonWithTitle:cancelStr];
////        [self createConfrimButtonWithTitle:confrimStr];
////    }
////    return self;
////}
////左侧“—“的点击事件
//-(void)leftButtonTarget
//{
//    //    TQCommodityDeatailHeaderView *fff = [[TQCommodityDeatailHeaderView alloc]init];
//    //
//    //    if ([_textFild.text isEqualToString:@"1"])//这个是文本框记录嘛_textFild
//    //    {
//    //
//    //        _leftB.userInteractionEnabled = NO ;//左侧按钮记录嘛
//    //
//    //        fff.tf = _textFild ;
//    //
//    //    }
//    //    else
//    //    {
//    //        _tF-=1;//文本框的文字嘛
//    //        //        NSLog(@"%ld",(long)_tF) ;
//    //        _textFild.text = [NSString stringWithFormat:@"%ld",(long)_tF] ;
//    //
//    //        fff.tf = _textFild ;
//    //    }
//    
//    
//}
////右侧”+“的点击事件
//-(void)rightButtonTarget
//{
//    //    _tF+=1;
//    //    //    NSLog(@"%ld",(long)_tF) ;
//    //    _textFild.text = [NSString stringWithFormat:@"%ld",(long)_tF] ;
//    //    _leftB.userInteractionEnabled = YES ;
//    //    TQCommodityDeatailHeaderView *fff = [[TQCommodityDeatailHeaderView alloc]init];
//    //    fff.tf = _textFild ;
//}
//#pragma mark - textFildDelegate
//-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
//{
//    return NO;
//}
//
//#pragma mark - 出现
//- (void)show{
//    //开始动画
//    [self animateStart];
//}
//
//#pragma mark - 创建window
//- (void)createWindow{
//    self.wnd = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//    self.frame = self.wnd.frame;
//    self.backgroundColor =[UIColor blackColor];
//    self.alpha = 0;
//    [self.wnd addSubview:self];
//    [self.wnd makeKeyAndVisible];
//}
//
//#pragma mark - 创建contentView
//- (void)createContentView{
//    self.contentView = [[UIView alloc] initWithFrame:CGRectMake(TGCaculate(63), TGCaculate(253), TGCaculate(238), TGCaculate(171))];
//    self.contentView.backgroundColor = [UIColor whiteColor];
//    self.contentView.transform = CGAffineTransformMakeScale(2.0, 2.0);
//    self.contentView.alpha = 0;
//    [self.wnd addSubview:self.contentView];
//}
//
//#pragma mark - 创建标题
//- (void)createTitleWithFrame:(CGRect)frame AndTitle:(NSString *)title AndTag:(NSInteger)tag{
//    UILabel * titleView = [[UILabel alloc] initWithFrame:frame];
//    titleView.text = title;
//    titleView.textAlignment = NSTextAlignmentCenter;
//    //    titleView.textColor = RGB(51, 51, 51);
//    titleView.textColor = RGB(0, 175, 188) ;
//    titleView.font = [UIFont systemFontOfSize:TGCaculate(13)];
//    titleView.tag = tag + 100;
//    [self.contentView addSubview:titleView];
//}
//
//#pragma mark - 创建线条
//- (void)createLine{
//    self.hLine = [[UIView alloc] initWithFrame:CGRectMake(0, TGCaculate(125), TGCaculate(238), 1)];
//    self.hLine.backgroundColor = RGB(153, 153, 153);
//    [self.contentView addSubview:self.hLine];
//    
//    self.vLine = [[UIView alloc] initWithFrame:CGRectMake(TGCaculate(118.5), self.hLine.bottom + TGCaculate(7), TGCaculate(1), TGCaculate(31))];
//    self.vLine.backgroundColor = RGB(153, 153, 153);
//    [self.contentView addSubview:self.vLine];
//}
//
//#pragma mark - 创建取消按钮
//- (void)createCancelButtonWithTitle:(NSString *)title{
//    self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.cancelButton.frame = CGRectMake(0, self.hLine.bottom, TGCaculate(118.5), TGCaculate(45));
//    self.cancelButton.titleLabel.font = [UIFont systemFontOfSize:TGCaculate(13)];
//    [self.cancelButton setTitle:title forState:UIControlStateNormal];
//    [self.cancelButton setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
//    [self.cancelButton addTarget:self action:@selector(cancelButtonTarget) forControlEvents:UIControlEventTouchUpInside];
//    [self.contentView addSubview:self.cancelButton];
//}
//
//#pragma mark - 取消按钮点击事件
//- (void)cancelButtonTarget{
//    [self endAnimateWithHaveTarget:NO];
//}
//
//#pragma mark - 创建确认按钮
//- (void)createConfrimButtonWithTitle:(NSString *)title{
//    self.confrimButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.confrimButton.frame = CGRectMake(self.vLine.right, self.hLine.bottom, TGCaculate(118.5), TGCaculate(45));
//    self.confrimButton.titleLabel.font = [UIFont systemFontOfSize:TGCaculate(13)];
//    [self.confrimButton setTitle:title forState:UIControlStateNormal];
//    [self.confrimButton setTitleColor:RGB(0, 175, 188) forState:UIControlStateNormal];
//    [self.confrimButton addTarget:self action:@selector(confrimButtonTarget) forControlEvents:UIControlEventTouchUpInside];
//    [self.contentView addSubview:self.confrimButton];
//}
//
//#pragma mark - 确认按钮点击事件
//- (void)confrimButtonTarget
//{
//    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"preSurezz" object:self userInfo:@{@"freeBuyNumber":[NSString stringWithFormat:@"%ld",(long)_tF]}];
//    //
//    //    [self endAnimateWithHaveTarget:YES];
//    
//}
//
//#pragma mark - 开始动画
//- (void)animateStart{
//    __weak typeof(self) weakSelf = self;
//    [UIView animateWithDuration:0.3 animations:^{
//        weakSelf.alpha = 0.5;
//        weakSelf.contentView.transform = CGAffineTransformMakeScale(1.0, 1.0);
//        weakSelf.contentView.alpha = 1;
//    }];
//}
//
//#pragma mark - 页面点击事件
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    [super touchesBegan:touches withEvent:event];
//    [self endAnimateWithHaveTarget:NO];
//}
//
//#pragma mark - 结束动画
//- (void)endAnimateWithHaveTarget:(BOOL)haveTarget{
//    if (haveTarget) {
//        _confrimBlock();
//    }
//    __weak typeof(self) weakSelf = self;
//    [UIView animateWithDuration:0.2 animations:^{
//        weakSelf.alpha = 0;
//        weakSelf.contentView.transform = CGAffineTransformMakeScale(2.0, 2.0);
//        weakSelf.contentView.alpha = 0;
//    } completion:^(BOOL finished) {
//        [weakSelf.cancelButton removeFromSuperview];
//        weakSelf.cancelButton = nil;
//        [weakSelf.confrimButton removeFromSuperview];
//        weakSelf.confrimButton = nil;
//        for (int i = 0; i < weakSelf.titleArray.count; i++) {
//            UILabel * titleView = [weakSelf.contentView viewWithTag:(i + 100)];
//            [titleView removeFromSuperview];
//            titleView = nil;
//        }
//        [weakSelf.vLine removeFromSuperview];
//        weakSelf.vLine = nil;
//        [weakSelf.hLine removeFromSuperview];
//        weakSelf.hLine = nil;
//        [weakSelf.contentView removeFromSuperview];
//        weakSelf.contentView = nil;
//        [weakSelf removeFromSuperview];
//        [weakSelf.wnd resignKeyWindow];
//        weakSelf.wnd = nil;
//    }];
//}
//
///************************************自动消失的alertView****************************/
//+(instancetype)createWithTitle:(NSString *)title{
//    TGAlertView * alert = [[TGAlertView alloc] initWithTitle:title];
//    return alert;
//}
//
//- (instancetype)initWithTitle:(NSString *)title{
//    self = [super init];
//    if (self) {
//        if ([title isEqualToString:@""] || title == nil) {
//            return self;
//        }
//        
//        self.userInteractionEnabled = NO;
//        
//        CGFloat width = title.length * TGCaculate(10) + TGCaculate(60);
//        CGFloat x = (ScreenWidth - width) / 2;
//        
//        [self createWindow];
//        self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, TGCaculate(300), width, TGCaculate(50))];
//        self.contentLabel.textColor = [UIColor whiteColor];
//        self.contentLabel.textAlignment = NSTextAlignmentCenter;
//        self.contentLabel.backgroundColor = [UIColor blackColor];
//        self.contentLabel.alpha = 0;
//        self.contentLabel.text = title;
//        self.contentLabel.font = [UIFont systemFontOfSize:TGCaculate(13)];
//        self.contentLabel.layer.cornerRadius =  TGCaculate(10);
//        self.contentLabel.layer.masksToBounds = YES;
//        [self.wnd addSubview:self.contentLabel];
//        
//        __weak typeof(self) weakSelf = self;
//        [UIView animateWithDuration:0.3 animations:^{
//            weakSelf.alpha = 0.3;
//            weakSelf.contentLabel.alpha = 0.7;
//        } completion:^(BOOL finished) {
//            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//                [UIView animateWithDuration:0.3 animations:^{
//                    weakSelf.alpha = 0;
//                    weakSelf.contentLabel.alpha = 0;
//                } completion:^(BOOL finished) {
//                    [weakSelf.contentLabel removeFromSuperview];
//                    weakSelf.contentLabel = nil;
//                    [weakSelf removeFromSuperview];
//                    [weakSelf.wnd resignKeyWindow];
//                    weakSelf.wnd = nil;
//                }];
//            });
//        }];
//    }
//    return self;
//}
//
//@end
